
package linuxbox.bbs.servlet;

import javax.servlet.http.*;

import linuxbox.bbs.bean.*;
import linuxbox.bbs.logic.*;
import linuxbox.common.*;
import linuxbox.exception.*;

public class BbsProposeFormAction extends Action {
    protected static String successJSP = null;
    
    public void doAction(HttpSession aSession, BoxSession aBoxSession, 
    HttpServletRequest req, HttpServletResponse res) throws Exception {
        String sUserName = aBoxSession.getUserName();

        String sCatID = req.getParameter("CAT_ID");
        int iCatID = 0;
        if (sCatID == null || sCatID.equals(""))
            throw new LinuxboxException(ExceptionHelper.BBS, "B000001");
        else
            iCatID = Integer.parseInt(sCatID);

        BbsManager bm = BbsManager.getInstance();
        String sCatName = bm.getCatName(iCatID);

        req.setAttribute("CAT_ID", sCatID); 
        req.setAttribute("CAT_NAME", sCatName);
        req.setAttribute("USER_NAME", sUserName);       

        String topic_id = "-1";
        String msg_id = "-1";
        String ind_lvl = "0";
        String subject = "";
        String msg_body = "";

        String sMsgID = req.getParameter("MSG_ID");
        if (sMsgID != null && sMsgID.length() > 0) {  
            long lMsgID = Long.parseLong(sMsgID);          

            if (lMsgID > 0) {
                BbsMsgKey key = new BbsMsgKey(lMsgID);
                BbsMsg msg = bm.getBbsMsg(key);
        
                topic_id = Long.toString(msg.getTopicID());
                msg_id = sMsgID;
                ind_lvl = Integer.toString(msg.getIndLvl());
                subject = msg.getSubject();
                msg_body = msg.getMsgBody();
            }
        }

        req.setAttribute("TOPIC_ID", topic_id);
        req.setAttribute("MSG_ID", msg_id);
        req.setAttribute("IND_LVL", ind_lvl);
        req.setAttribute("SUBJECT", subject);
        req.setAttribute("MSG_BODY", msg_body);

        sendFile(successJSP, req, res);
    }

    public void setSuccessJSP(String str) {
        //"/jsp/bbs/BbsProposeForm.jsp"
        successJSP = str;
    }
}
